﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Skynet.CommonLibrary.ThreadRefreshTime.Attribute
{
    /// <summary>
    /// 获取该程序集下的所有标注为任务的特性
    /// </summary>
    ///<remarks>
    /// 作者：         李志强
    /// 开发时间：  2011-03-28
    /// </remarks>
    public  class TaskAttributeHelp
    {
        public static List<TaskActionAttribute> GetAppDomainTask
        {
            get
            {
                List<TaskActionAttribute> taskList = new List<TaskActionAttribute>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    var types = assembly.GetTypes().Where(o => o.IsDefined(typeof(TaskActionAttribute), false));
                    if (types != null)
                    {
                        foreach (Type t in types)
                        {
                            object[] objs = t.GetCustomAttributes(typeof(TaskActionAttribute), false);
                            if (objs != null)
                            {
                                foreach (object ob in objs)
                                {
                                    TaskActionAttribute taa = ob as TaskActionAttribute;
                                    taa.ClassType = t;
                                    taskList.Add(taa);
                                }
                            }
                        }
                    }
                }
                return taskList;
            }
        }
    }
}
